<?php
require_once 'observer/QuickObservable.php';
require_once 'observer/Observable.php';
require_once 'observer/Observe.php';
require_once 'observer/QuickLogest.php';
require_once 'duck/DuckInterface.php';
require_once 'adapt/EAdaptObserve.php';
require_once 'e/E.php';
require_once 'duckObserve/DuckGreen.php';
require_once 'duckObserve/DuckRed.php';
require_once 'decker/DuckDecker.php';
require_once 'factory/DuckFactoryInterface.php';
require_once 'factory/DuckFactory1.php';
require_once 'flock/FlockDuck.php';

class DuckSimulator {
    protected $ducks;

    public function setDuck(DuckInterface $d)
    {
        $this->ducks[] = $d;
    }

    public function quick()
    {
        foreach ($this->ducks as $duck)
        {
            $duck->quick();
            echo "<br>";
        }
    }

    public function getQuickCount()
    {
        $count = 0;
        foreach ($this->ducks as $duck)
        {
            $count += $duck->getQuick();
        }
        return $count;
    }
}

$countDuckFactory = new DuckFactory1();
//创建一群鸭子
$duck1 = $countDuckFactory->createRedDuck();
$duck2 = $countDuckFactory->createGreenDuck();
$duck3 = $countDuckFactory->createRedDuck();
$duck4 = $countDuckFactory->createE();

$quickLogest = new QuickLogest();
$duck1->register($quickLogest);
$duck2->register($quickLogest);
$duck3->register($quickLogest);
$duck4->register($quickLogest);

$DuckSimulator = new DuckSimulator();
$DuckSimulator->setDuck($duck1);
$DuckSimulator->setDuck($duck2);
$DuckSimulator->setDuck($duck3);
$DuckSimulator->setDuck($duck4);
$DuckSimulator->quick();

